#include <sdk.h> // Code::Blocks SDK
#include <cbstyledtextctrl.h>
#include "CodePasteConfig.h"
#include "CodePaste.h"

extern CodePasteSettings settings;

BEGIN_EVENT_TABLE(CodePasteConfigurationPanel, wxPanel)
   //EVENTS HERE
END_EVENT_TABLE()

CodePasteConfigurationPanel::CodePasteConfigurationPanel(wxWindow *parent, CodePasteSettings *settings)
{
   Create(parent, wxID_ANY);
   set = settings;
   thePanel = new cpgPanel(this);
   Sync();
}

CodePasteConfigurationPanel::~CodePasteConfigurationPanel() {}

void CodePasteConfigurationPanel::Sync()
{
   thePanel->txtDevKey->SetValue(set->dev_key);
   thePanel->txtDefaultTitle->SetValue(set->default_title);
   thePanel->chkConfirmTitle->SetValue(set->confirm_title);
   thePanel->chSyntax->Clear();
   for(unsigned int i = 0; i < numSyntaxes; ++i)
   {
      thePanel->chSyntax->Insert(syntaxes[i].language, i);
   }
   thePanel->chSyntax->Select(set->syntax_choice);
   thePanel->chkAutoSyntax->SetValue(set->auto_syntax);
   thePanel->chDuration->Clear();
   for(unsigned int j = 0; j < numExpirations; ++j)
   {
      thePanel->chDuration->Insert(expirations[j].expires, j);
   }
   thePanel->chDuration->Select(set->expiration_choice);
   thePanel->chExposure->Select(set->exposure_choice);
   thePanel->chkCopyLink->SetValue(set->copy_to_clipboard);
   thePanel->chkOpenLink->SetValue(set->open_in_browser);
   thePanel->sldTimeout->SetValue(set->timeout);
}

void CodePasteConfigurationPanel::OnApply()
{
   set->dev_key = thePanel->txtDevKey->GetValue();
   set->default_title = thePanel->txtDefaultTitle->GetValue();
   set->confirm_title = thePanel->chkConfirmTitle->IsChecked();
   set->syntax_choice = thePanel->chSyntax->GetSelection();
   set->auto_syntax = thePanel->chkAutoSyntax->IsChecked();
   set->exposure_choice = thePanel->chExposure->GetSelection();
   set->expiration_choice = thePanel->chDuration->GetSelection();
   set->timeout = thePanel->sldTimeout->GetValue();
   set->copy_to_clipboard = thePanel->chkCopyLink->IsChecked();
   set->open_in_browser = thePanel->chkOpenLink->IsChecked();
}

void CodePasteConfigurationPanel::OnCancel() { }
